package com.zq.it.dao.impl.exam;

import java.util.Collection;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zq.it.dao.exam.TExamDAO;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.exam.TExam;

/**
 * TExamDAO的实现类
 *
 * @author 王凡
 *
 * @version $ID: TExamDAOImpl.java 2013-3-21 王凡@$
 */
public class TExamDAOImpl extends BaseDao<TExam> implements TExamDAO {

	private static final Logger log = LoggerFactory
			.getLogger(TExamDAOImpl.class);
	// property constants
	public static final String _SANWSER = "SAnwser";
	public static final String SCORE = "score";
	public static final String _QTYPE = "QType";
	public static final String EXTEND_FIELD = "extendField";

	@Override
	public void save(TExam transientInstance) {
		log.debug("saving TExam instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void delete(TExam persistentInstance) {
		log.debug("deleting TExam instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	@Override
	public TExam findById(Long id) {
		log.debug("getting TExam instance with id: " + id);
		try {
			TExam instance = (TExam) getHibernateTemplate()
					.get("com.zq.it.pojo.exam.TExam", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public List findByExample(TExam instance) {
		log.debug("finding TExam instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TExam instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TExam as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	public List findBySAnwser(Object SAnwser) {
		return findByProperty(_SANWSER, SAnwser);
	}

	@Override
	public List findByScore(Object score) {
		return findByProperty(SCORE, score);
	}

	@Override
	public List findByQType(Object QType) {
		return findByProperty(_QTYPE, QType);
	}

	@Override
	public List findByExtendField(Object extendField) {
		return findByProperty(EXTEND_FIELD, extendField);
	}

	@Override
	public List findAll() {
		log.debug("finding all TExam instances");
		try {
			String queryString = "from TExam";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@Override
	public void update(TExam instance) {
		log.debug("attaching dirty TExam instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@Override
	public void saveAll(Collection list) {
		log.debug("saving TExam Collection instance");
		try {
			getHibernateTemplate().saveOrUpdateAll(list);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void deleteByHql(String hql) {
		super.deleteEntity(hql);
	}

	@Override
	public List findByHql(String hql) {
		return getHibernateTemplate().find(hql);
	}
}